package com.bt.lms.ui.action.school_education.transferin_info;

import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

/**
 * 学籍异动信息添加功能事件
 */
public class TransferInfoAddAction implements EventHandler {

    private VBox box;
    private Integer baseWidth = 1200;

    private HBox one;

    public TransferInfoAddAction(VBox totalVBox, HBox one) {
        this.box = totalVBox;
        this.one = one;
    }
    @Override
    public void handle(Event event) {
        VBox vBox = new VBox();
        HBox btnBox = new HBox();
        btnBox.setPrefWidth(baseWidth);
        btnBox.setAlignment(Pos.CENTER_RIGHT);
        btnBox.setSpacing(10);
        Insets insets1 = new Insets(10,50,10,10);
        btnBox.setPadding(insets1);
        Button saveBtn = new Button("保存");
        Button cancelBtn = new Button("取消");
        btnBox.getChildren().add(saveBtn);
        btnBox.getChildren().add(cancelBtn);
        BtnStyle.saveBtn(saveBtn);
        BtnStyle.cancelBtn(cancelBtn);
        saveBtn.setCursor(Cursor.HAND);
        cancelBtn.setCursor(Cursor.HAND);

        ObservableList<Node> children = this.box.getChildren();
        vBox.getChildren().add(btnBox);

        //添加事件
        AddTransferInfoVerify addTransferInfoVerify = new AddTransferInfoVerify(this.box,this.one);
        saveBtn.setOnAction(addTransferInfoVerify);

        //学习简历信息的主盒子
        VBox totalVBox = new VBox();
        totalVBox.setPrefWidth(baseWidth);
        totalVBox.setSpacing(10);


        Integer width = baseWidth/9;
        Integer widthMes = baseWidth/3;
        HBox one = new HBox();
        one.setPrefWidth(baseWidth);
        one.setSpacing(10);
        Label anomalousClassLab = new Label("异动类别");
        anomalousClassLab.setPrefWidth(width);
        ComboBox anomalousClassCB = new ComboBox<>();
        anomalousClassCB.setPrefWidth(widthMes);
        anomalousClassCB.getItems().addAll("停学","休学","停复","休复","退学","转专业");
        anomalousClassCB.setId("anomalousClassCB");
        Label oldChangeStatusLab = new Label("异动前学籍状态");
        oldChangeStatusLab.setPrefWidth(width);
        ComboBox oldChangeStatusTF = new ComboBox<>();
        oldChangeStatusTF.getItems().addAll("在籍","未注册","休学","退学","开除","毕业","异动中");
        oldChangeStatusTF.setId("oldChangeStatusTF");
        one.getChildren().addAll(anomalousClassLab,anomalousClassCB,oldChangeStatusLab,oldChangeStatusTF);
        totalVBox.getChildren().add(one);

        HBox two = new HBox();
        two.setPrefWidth(baseWidth);
        two.setSpacing(10);
        Label changeReasonLab = new Label("异动原因");
        changeReasonLab.setPrefWidth(width);
        TextField changeReasonTF = new TextField();
        changeReasonTF.setPrefWidth(widthMes);
        changeReasonTF.setId("changeReasonTF");
        Label newChangeStatusLab = new Label("异动后学籍状态");
        newChangeStatusLab.setPrefWidth(width);
        ComboBox newChangeStatusCB = new ComboBox<>();
        newChangeStatusCB.getItems().addAll("在籍","未注册","休学","退学","开除","毕业","异动中");
        newChangeStatusCB.setId("newChangeStatusCB");
        two.getChildren().addAll(changeReasonLab,changeReasonTF,newChangeStatusLab,newChangeStatusCB);
        totalVBox.getChildren().add(two);

        HBox three = new HBox();
        three.setPrefWidth(baseWidth);
        three.setSpacing(10);
        Label changeDateLab = new Label("异动日期");
        changeDateLab.setPrefWidth(width);
        DatePicker changeDateDP = new DatePicker();
        changeDateDP.setPrefWidth(widthMes);
        changeDateDP.setId("changeDateDP");
        three.getChildren().addAll(changeDateLab,changeDateDP);
        totalVBox.getChildren().add(three);


        HBox four = new HBox();
        four.setPrefWidth(baseWidth);
        four.setSpacing(10);
        Label explainLab = new Label("异动说明");
        explainLab.setPrefWidth(width);
        TextArea explainAR = new TextArea();
        explainAR.setPrefWidth(baseWidth-300);
        explainAR.setMaxHeight(100);
        explainAR.setId("explainAR");
        four.getChildren().addAll(explainLab,explainAR);
        totalVBox.getChildren().add(four);
        vBox.getChildren().add(totalVBox);
        children.add(vBox);

        /**
         * 取消按钮事件
         */
        cancelBtn.setOnAction(event1 -> {
            children.remove(4);
        });
    }
}
